function hideDiv(div_id) {
	$("#" + div_id).animate({
		opacity : "hide"
	}, 300);
}
function popupDiv(div_id) {
	var div_obj = $("#" + div_id);
	// 窗口宽度,高度
	var winWidth = $(window).width();
	var winHeight = $(window).height();
	// 弹出的div的宽度,高度
	var popHeight = div_obj.height();
	var popWidth = div_obj.width();
	div_obj.animate({
		opacity : "show",
		left : (winWidth - popWidth) / 2,
		top : (winHeight - popHeight) / 2,
		width : popWidth,
		height : popHeight
	}, 300);
}
// 课程修改的js事件
$(function() {
	$("#AddTeacher_div").easydrag();
	$("#AddTeacher_div").setHandler("#AddTeacher_div #AddTeacher_head");
});

$(function() {
	$("#updateTeacher_div").easydrag();
	$("#updateTeacher_div")
			.setHandler("#updateTeacher_div #updateTeacher_head");
});

function clickUpdateTeacher(id) {
	TeacherManager.getById(id, function(data) {
		$("#teacherid").val(data.id);
		$("#TeacherId").html(data.id);
		$("#teachername").val(data.name);
	});
	popupDiv('updateTeacher_div');
}

function updateTeacher() {
	if(!RolePowerManager())
	{
		return;
	}
	if ($("#teachername").val()) {
		TeacherManager.updateTeacher($("#teacherid").val(), $("#teachername")
				.val(), function(data) {
			if (data) {
				alert("修改成功");
				location.reload();
			} else {
				alert("修改失败");
			}
		});
	} else {
		alert("请输入讲师姓名");
	}

}
function popadd()
{
	if(!RolePowerManager())
	{
		return;
	}
	popupDiv('AddTeacher_div');
}
// 增加一个讲师
function addTeacher() {
	if ($("#inputTeachername").val()) {
		TeacherManager.addTeacher($("#inputTeachername").val(), function(data) {
			if (data) {
				alert("增加成功");
				location.href = "FindTeacherServlet";
			} else {
				alert("增加失败");
			}
		});
	} else {
		alert("请输入讲师姓名");
	}
}
// 删除一个讲师
function deleteTeacher(id) {
	if(!RolePowerManager())
	{
		return;
	}
	if(!confirm("是否确定删除 ？"))
	{
		return;
	}
	TeacherManager.deleteById(id, function(data) {
		if (data) {
			alert("删除成功");
			location.href = "FindTeacherServlet";
		} else {
			alert("删除失败");
		}
	});
}
function search() {
	if ($("#serchtype").val() == "teacherid") {
		if (isNaN($("#keycode").val())) {
			alert("请输入数字");
			return;
		}
	}
	$("#searchform").submit();
}

function changePageSize()
{
	var pageSize=$("#pageSize").val();
	location.href="FindTeacherServlet?pageSize="+pageSize;
}